#include <iostream>
using namespace std;

//虚函数可以让子类作为参数调用时 编译器能够正确的调用子类的方法
//纯虚函数 子类必须要实现

class Fish
{
public:
    Fish()
    {
        cout << "Constructed Fish" << endl;
    }
    //将析构函数定义为虚函数 确保通过基类指针调用delete时, 将调用派生类的析构函数
    virtual ~Fish()
    {
        cout << "Destoryed Fish" << endl;
    }
};

class Tuna:public Fish
{
public:
    Tuna()
    {
        cout << "Constructed Tuna" << endl;
    }
    ~Tuna()
    {
        cout << "Destroyed Tuna" << endl;
    }
};

void DeleteFishMemory(Fish* pFish)
{
    delete pFish;
}

int main()
{
    cout << "Allocating a Tuna on the free store" << endl;
    //自由内存区申请一个tuna对象, 并存储到指针变量pTuna
    Tuna* pTuna = new Tuna;
    cout << "tring to delete the tuna:" << endl;
    DeleteFishMemory(pTuna);
    cout << "Establishing a Tuna on the stack:" << endl;
    Tuna mydinner;
    cout << "my dinner releases automatically" << endl;
    return 0;
}
